/** @file svm_arguments.h
 *
 *  @author Dongryeol Lee (drselee@gmail.com)
 */

#ifndef MLPACK_SVM_SVM_ARGUMENTS_H
#define MLPACK_SVM_SVM_ARGUMENTS_H

#include "core/abstract/abstract_arguments.h"

namespace mlpack {
namespace svm {

class SVMArguments : public core::abstract::AbstractArguments {
  public:
    double lambda_;

    int num_random_train_samples_per_iter_;

  public:

    SVMArguments() {

      // Default values.
      lambda_ = 1.0;
      num_random_train_samples_per_iter_ = 1;

      // Add more descriptions.
      desc_->add_options()(
        "lambda_in",
        boost::program_options::value<double>()->default_value(1.0),
        "OPTIONAL The lambda regularziation for the Pegasos optimizer."
      )(
        "num_random_train_samples_per_iter_in",
        boost::program_options::value<int>()->default_value(1),
        "OPTIONAL The number of train samples to use per iteration."
      );
    }

  private:

    bool Validate_() const {

      if(vm_["lambda_in"].as<double>() <= 0.0) {
        std::cerr << "The --lambda_in requires a positive real number.\n";
        return false;
      }
      if(vm_["num_random_train_samples_per_iter_in"].as<int>() <= 0) {
        std::cerr << "The --num_random_train_samples_per_iter_in requires a " <<
                  "positive integer.\n";
        return false;
      }
      return true;
    }

    bool Parse_(
      boost::mpi::communicator &world,
      const std::vector< std::string > & args) {

      // Validate the arguments.
      if(! this->Validate_()) {
        return false;
      }

      lambda_ = vm_["lambda_in"].as<double>();
      num_random_train_samples_per_iter_ =
        vm_["num_random_train_samples_per_iter_in"].as<int>();
      return false;
    }
};
}
}

#endif
